<template>
  <div>
    <div class="warn-top">
      <h4 style="text-align: left; color: #126bff; margin-bottom: 20px">
        安保人员管理
      </h4>
      <el-form
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="90px"
        style="display: flex; flex-wrap: wrap"
      >
        <el-form-item
          label="护卫学校名称:"
          prop="dwmc"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.dwmc"
            placeholder="请输入护卫学校名称"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="申请人姓名:"
          prop="xm"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.xm"
            placeholder="请输入申请人姓名"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="身份证号码:"
          prop="gmsfhm"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.gmsfhm"
            placeholder="请输入身份证号码"
            clearable
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <!-- <el-form-item label="审批状态:" style="width: 450px; float: left">
          <el-select
            v-model="formData.appltStatus"
            clearable
            placeholder="请选择审批状态"
            :style="{ width: '300px' }"
            @change="select"
          >
            <el-option
              v-for="item in appltStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item
          label="添加时段："
          prop="time"
          style="width: 450px; float: left"
          label-width="84px"
        >
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '300px' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="small " id="ccBtn" style="float: right">
          <el-button @click="resetForm()" id="reset">重置</el-button>
          <el-button
            type="primary"
            @click="submitForm(formData)"
            id="submitForm"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="warn-content" style="width: 100%">
      <!-- <p style="display: flex">
        审批默认通过：
        <el-switch
          style="display: block"
          v-model="value2"
          active-color="#13ce66"
          inactive-color="#FF4444"
          active-text="开启"
          inactive-text="关闭"
          @change="applAll"
        >
        </el-switch>
      </p> -->

      <el-table :data="tableData" style="width: 100%; cursor: pointer">
        <el-table-column prop="id" label="序号" width="100">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <el-table-column prop="photo" label="申请人照片">
          <template slot-scope="scope">
            <el-image
              style="
                width: 50px;
                height: 50px;
                padding: 5px;
                box-sizing: border-box;
              "
              :src="scope.row.photo"
              v-if="scope.row.photo"
              :preview-src-list="[scope.row.photo]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="xm" label="申请人姓名"> </el-table-column>
        <el-table-column prop="xbdm" label="性别">
          <template slot-scope="scope">
            {{ scope.row.xbdm == "0" ? "男" : "女" }}
          </template>
        </el-table-column>
        <el-table-column prop="dwmc" label="护卫学校名称"> </el-table-column>
        <el-table-column prop="tm_gmsfhm" label="身份证号码" width="180">
          <!-- <template slot-scope="scope">
            <span v-if="scope.row.showIdCard">{{ scope.row.gmsfhm }}</span>
            <span v-else>{{ scope.row.tm_gmsfhm }}</span>
            <el-button
              type="text"
              icon="el-icon-view"
              @click="scope.row.showIdCard = !scope.row.showIdCard"
            ></el-button>
          </template> -->
        </el-table-column>
        <el-table-column prop="xlmj_lxdh" label="联系方式" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.showPhone">{{ scope.row.xlmj_lxdh }}</span>
            <span v-else>{{ scope.row.tm_xlmj_lxdh }}</span>
            <el-button
              type="text"
              icon="el-icon-view"
              @click="scope.row.showPhone = !scope.row.showPhone"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column prop="dzmc" label="家庭地址"> </el-table-column>
        <el-table-column prop="mzdm" label="民族"> </el-table-column>
        <el-table-column prop="status" label="审批状态">
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <!-- <el-tag size="medium">{{ scope.row.status }}</el-tag> -->
              <el-tag
                style="color: #126bff; border: 1px #126bff solid"
                v-if="scope.row.status == 0"
                >待审批</el-tag
              >
              <el-tag
                style="color: #1cdc7c; border: 1px #1cdc7c solid"
                v-if="scope.row.status == 1"
                type="success"
                >已通过</el-tag
              >
              <el-tag
                style="color: #ff4444; border: 1px #ff4444 solid"
                v-if="scope.row.status == 2"
                type="danger"
                >未通过</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="申请时间" width="180">
        </el-table-column>
        <el-table-column label="操作">
          <!-- <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情0</el-button
            >
          </template> -->
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0">
              <el-button
                @click="detailClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >
              <el-button
                style="color: #1cdc7c"
                @click="successClick(scope.row)"
                type="text"
                size="small"
                >通过</el-button
              ><el-button
                style="color: #ff4444"
                @click="failClick(scope.row)"
                type="text"
                size="small"
                >拒绝</el-button
              >
            </div>
            <div v-if="scope.row.status != 0">
              <el-button
                @click="detailClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >
            </div>
          </template>
          <!-- <template slot-scope="scope" v-if="scope.row.status != 0">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
          </template> -->
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[20, 50, 100]"
        :page-size="pageSize"
        layout="total, prev, pager, next, sizes"
        :total="total"
        style="float: right; margin-top: 20px"
      >
      </el-pagination>
    </div>
    <!-- 弹窗 -->
    <div>
      <el-dialog
        title="详情"
        :visible.sync="dialogVisible"
        width="680px"
        style="border-radius: 20px"
        top="0"
      >
        <!-- xzqydm: "安次区",
          sspcs:'安次分局西小区派出所', -->
        <div class="body">
          <h3>安保人员</h3>
          <div style="display: flex; justify-content: space-between">
            <div class="title">
              <p>申请人姓名</p>
              <p>民族</p>
              <p>家庭住址</p>
              <p>申请人照片</p>
              <p>申请时间</p>
            </div>
            <div>
              <p>{{ detaile.xm }}</p>
              <p>{{ detaile.mzdm }}</p>
              <p>{{ detaile.dzmc }}</p>
              <p>
                <el-image
                  style="
                    width: 50px;
                    height: 50px;
                    padding: 5px;
                    box-sizing: border-box;
                  "
                  :src="detaile.photo"
                  :preview-src-list="[detaile.photo]"
                >
                </el-image>
              </p>
              <p>{{ detaile.create_time }}</p>
            </div>
            <div class="title">
              <p>性别</p>
              <p>身份证号码</p>
              <p>联系方式</p>
              <p>账号状态</p>
              <p></p>
            </div>
            <div>
              <p>{{ detaile.xbdm == 0 ? "男" : "女" }}</p>
              <p>
                {{ detaile.tm_gmsfhm }}
              </p>
              <p>
                <!-- <template slot-scope="scope"> -->
                <span v-if="!detaile.showPhone">{{
                  detaile.tm_xlmj_lxdh
                }}</span>
                <span v-else>{{ detaile.xlmj_lxdh }}</span>
                <el-button
                  type="text"
                  icon="el-icon-view"
                  @click="detaile.showPhone = !detaile.showPhone"
                ></el-button>
                <!-- </template> -->
              </p>
              <p>
                <span v-if="detaile.status == 1">
                  <el-button style="color: #1cdc7c" type="text" size="small"
                    >已通过</el-button
                  >
                </span>
                <span v-if="detaile.status == 0">
                  <el-button style="color: #126bff" type="text" size="small"
                    >待审批</el-button
                  >
                </span>
                <span v-if="detaile.status == 2">
                  <el-button style="color: #ff4444" type="text" size="small"
                    >已拒绝</el-button
                  >
                </span>
              </p>
              <p></p>
            </div>
          </div>
        </div>
        <el-button
          type="primary"
          @click="confirm"
          style="
            width: 205px;
            height: 40px;
            line-height: 16px;
            text-align: center;
            background: #126bff;
            opacity: 1;
            margin: 0 auto;
            margin-top: 10px;
            border-radius: 6px;
          "
          >关闭</el-button
        >
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { volunteergl } from "@/api/school/voluntee";
import { Loading } from "element-ui";
export default {
  name: "WARN",
  components: {},
  data() {
    return {
      total: null,
      currentPage4: 4,
      // pages: {
      // 按页数查询数据
      currentPage: 1,
      pageSize: 20,
      value: "",
      // },
      appltStatus: [
        {
          value: "1",
          label: "已通过",
        },
        {
          value: "2",
          label: "未通过",
        },
        {
          value: "0",
          label: "待审核",
        },
      ],
      formData: {
        dwmc: "",
        xm: "",
        time: "",
        gmsfhm: "",
        // appltStatus: "",
      },
      detaile: {},
      tableData: [],

      // 将条件搜索表单中的time 转为开始时间  截止时间
      searchData: {
        dwmc: "",
        xm: "", // 姓名
        xlrylbdm: "保安", // 护学岗人员类型
        gmsfhm: "", // 护学岗人员身份证号
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
        page: 1,
        pagesize: 20,
        token: JSON.parse(localStorage.getItem("userInfo")).token,
      },
      datalist: [],
      dialogVisible: false,
      value2: false, // 审批默认通过
    };
  },
  watch: {
    $route(to, from) {
      console.log(to, from);
    },
  },
  created() {
    console.log(666);
    // window.addEventListener
  },
  mounted() {
    this.initdata();
  },
  methods: {
    confirm(e) {
      this.dialogVisible = false;
    },
    initdata() {
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      volunteergl(this.searchData).then((res) => {
        console.log(res);
        if (res.code == 200) {
          loadingInstance.close();
          // console.log(res.data);
          res.data.res.forEach((item, index) => {
            res.data.res[index].create_time = this.$moment(
              item.create_time * 1000
            ).format("YYYY-MM-DD HH:mm:ss");
            item.showIdCard = false;
            item.showPhone = false;
          });
          that.tableData = res.data.res;
          that.total = res.data.count;
        }
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
      // this.formToSearch(this.formData);
      this.searchData = {
        xm: "", // 姓名
        xlrylbdm: "保安", // 护学岗人员类型
        gmsfhm: "", // 护学岗人员身份证号
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
        page: 1,
        pagesize: 20,
        token: JSON.parse(localStorage.getItem("userInfo")).token,
      };
      this.initdata();
    },
    // 将搜索条件格式处理
    formToSearch(formData) {
      this.searchData.dwmc = formData.dwmc;
      this.searchData.xm = formData.xm;
      this.searchData.gmsfhm = formData.gmsfhm;
      this.searchData.page = 1;
      this.searchData.pagesize = 20;
      if (formData.time == "" || formData.time == null || formData.time == []) {
        this.searchData.end_time = "";
        this.searchData.begin_time = "";
      } else {
        this.searchData.end_time = formData.time[1];
        this.searchData.begin_time = formData.time[0];
      }
      return this.searchData;
    },
    submitForm(formData) {
      console.log(formData);
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      console.log(this.formToSearch(this.formData));
      console.log(this.formData);
      volunteergl(this.formToSearch(this.formData)).then((res) => {
        console.log(res);
        if (res.code == 200) {
          console.log(res.data.res);
          res.data.res.forEach((item, index) => {
            res.data.res[index].create_time = that
              .$moment(item.create_time * 1000)
              .format("YYYY-MM-DD HH:mm:ss");

            // console.log(moment(item.create_time * 1000).format("YYYY-MM-DD"));
          });
          this.tableData = res.data.res;
          that.total = res.data.count;
          this.currentPage = 1; // 重置到第一页
          loadingInstance.close();
          console.log(that.tableData.length);
        } else if (res.code == 400) {
          this.$message({
            message: res.message,
            type: "warning",
            duration: "2000",
          });
        }
      });
    },
    detailClick(row) {
      console.log(row);
      this.dialogVisible = true;
      this.detaile = row;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.searchData.pagesize = val;
      this.searchData.page = 1;
      this.currentPage = 1;
      this.initdata();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.searchData.page = val;
      this.initdata();
      this.currentPage = val;
    },
    select(e) {
      console.log(e);
    },
    applAll(e) {
      console.log(e);
      if (e == true) {
        console.log("开启默认通过");
        this.tableData.forEach((e) => {
          console.log(e.status);
          e.status = 1;
        });
      } else {
        console.log("关闭默认通过");
      }
    },
    successClick(e) {
      // 通过审核
      console.log(e.status);
      e.status = 1;
      this.dialogVisible = false;
    },
    failClick(e) {
      // 拒绝
      console.log(e.status);
      e.status = 2;
      this.dialogVisible = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.warn-top {
  // border: 1px red solid;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.warn-top /deep/[data-v-21354b7e] .el-form-item__content {
  border: none;
  width: auto;
  padding-left: 20px;
}

/deep/.el-range-editor--medium .el-range-separator {
  line-height: 21px;
  font-size: 14px;
}
/deep/ .el-range__icon {
  line-height: 21px;
}
// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
#ccBtn {
  /deep/.el-form-item__content {
    // border: 1px red solid !important;
    width: 200px !important;
  }
}
/ddep/#ccBtn > div {
  width: 123px !important;
}
/deep/.el-form-item__label {
  // border: 1px red solid;
  width: 120px !important;
}
.warn-content {
  margin-top: 20px;
  // border: 1px red solid;
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
  overflow: auto;
}

.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
.upIpfo {
  display: flex;
  width: 100%;
  // border: 1px red solid;
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  // border: 1px red solid;
  display: inline-block;
  // background-color: skyblue;
}
/deep/.el-range-editor--medium .el-range-separator {
  line-height: 21px;
  font-size: 14px;
  height: 21px;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.el-input--medium .el-input__icon {
  line-height: 30px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }
/deep/.el-dialog {
  border-radius: 15px !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 0 20px 20px 20px !important;
}
// /deep/.el-dialog__body tbody > .el-table__row {
//   color: red !important;
//   /deep/.el-table_1_column_5 {
//     color: red !important;
//   }
// }
/deep/.el-input--suffix .el-input__inner {
  padding-right: 0px;
}
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
  border-radius: 6px !important;
}
// el-table_1_column_5   el-table__cell
.rowText {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
/deep/.el-switch__label.is-active {
  color: #ff4444;
}
.success {
  margin-right: 15px;
  width: 76px;
  height: 36px;
  background: #1cdc7c;
  border-radius: 10px;
  opacity: 1;
  border: none;
  color: #ffffff;
}
.refuse {
  width: 76px;
  height: 36px;
  background: #ff4444;
  border-radius: 10px;
  opacity: 1;
  border: none;
  color: #ffffff;
}
::v-deep.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px !important;
  height: 21px !important;
  font-size: 16px !important;
  color: #13213b !important;
}

.title {
  font-size: 14px;
  font-family: Microsoft YaHei-Bold, Microsoft YaHei;
  font-weight: bold;
  color: #13213b;
}
.body {
  width: 100%;
  height: auto;
  border-radius: 16px 16px 16px 16px;
  opacity: 1;
  border: 1px solid #d7dbe3;
}
.body h3 {
  width: 100%;
  text-align: center;
  height: 40px;
  line-height: 40px;
  background: #ecf5ff;
  border-radius: 16px 16px 0px 0px;
  opacity: 1;
  font-size: 20px;
  font-family: Microsoft YaHei-Bold, Microsoft YaHei;
  font-weight: bold;
  color: #13213b;
}
.body > div > div {
  border-right: 1px #d7dbe3 solid;
  width: 25%;
  display: flex;
  flex-direction: row;
  align-content: stretch;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
}

.body > div > div:nth-last-of-type(1) {
  border-right: none;
}
.body > div > div > p {
  border-right: none;
  border-left: none;
  border-top: 1px #d7dbe3 solid;
  // background-color: #d7dbe3;
  // background-color: red;
}
/deep/.body p {
  // border: 1px red solid;
  width: 100%;
  height: 55px !important;
  // line-height: 50px;
  text-align: center;
  display: flex;
  align-content: flex-end;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
}
</style>

